package com.naml.h_objectstream;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * @author marin
 * @version 1.0
 * @date 2025/4/24 21:07
 * @desc 对象输出流，用于序列化操作
 */
@SuppressWarnings("all")
public class ObjectOutputStream01 {
    public static void main(String[] args) {
        //可以通过diaGrams查看对象输出流，其实也是利用了修饰器设计模式
        String path = "/Users/marin/xulie.dat";
        ObjectOutputStream oos = null;
        try {
            oos = new ObjectOutputStream(new FileOutputStream(path));
            //序列化一些参数值+数据类型
            oos.writeInt(100);
            oos.writeBoolean(true);
            oos.writeChar('a');
            oos.writeUTF("我开始序列化了");
            oos.writeDouble(11.1d);
            oos.writeFloat(12.2f);
            oos.writeLong(Long.MAX_VALUE);
            oos.writeObject(new Dog("花花",4,"88斤","三花色"));
            System.out.println("序列化数据完毕...");
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            //关流
            try {
                oos.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
